#include "winos.h"

_SSL_BEGIN
_SSWINOSL_BEGIN

_SSBASEL_USE_NP

class thread_runable_interface
{
public:
	virtual unsigned int run() = 0;
	virtual bool stop_request() = 0;
};

class SSWINOS_CLASS win_thread
{
public:
	win_thread();
	virtual ~win_thread();

public:
	bool start(thread_runable_interface *runable = NULL, size_t stack_size = 0);

	// Try stop it elegantly; then force stop it.
	bool stop(unsigned long milliseconds = 5000);

	// Try wait for thread exit in timeout; then false
	bool join(unsigned long milliseconds = INFINITE, unsigned long *exit_code = NULL);

	// After that, you must manager the HANDLE by yourself
	HANDLE detach();

	bool suspend();
	bool resume();

	bool get_exitcode(unsigned long *exit_code);

	bool is_runing();

protected:
	virtual unsigned int run();
	virtual bool stop_request();

private:
	static unsigned int __stdcall s_thread_proc(void* param);

protected:
	HANDLE thread_;
	unsigned int thread_id_;
	thread_runable_interface *runable_;
};

_SSWINOSL_END
_SSL_END

